<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<html>
<HEAD>
<%@ page import="java.sql.*,java.util.*"%>
<%@ page import="gdufs.stat.service.Utils"%>
<%@ page import="gdufs.stat.service.vo.Semester"%>
<%@page import="gdufs.stat.service.CourseQuery"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<TITLE>课程表</TITLE>
<%@include file="/inc/head.jsp"%>
<script type="text/javascript">
	function doSubmit(flag) {
		var xn = document.getElementById("xn").value;
		var xq = document.getElementById("xq").value;
		var weekStr = document.getElementById("week").value;
		var week = parseInt(weekStr);
		week = week + flag;
		window.location.href = "kcb.jsp?xn="+xn+"&xq="+xq+"&week="+week;
	}
</script>
<style type="text/css">
#kcb {
	border: 1px solid #cccccc;
	border-collapse: collapse;
	text-align: center;
}
.title {
	text-align: center;
	font-weight: bold;
}

.course{
	background:url("../images/dot.jpg");
	background-position: center;
	background-repeat: no-repeat;
	cursor: pointer;
	cursor: hand;
}

.current{
	background:url("../images/dot_red.jpg");
	background-position: center;
	background-repeat: no-repeat;
}

</style>
</HEAD>

<BODY>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application); 
CourseQuery courseQuery = (CourseQuery)context.getBean("courseQuery");
%>
<%
	String xn = request.getParameter("xn");
	String xq = request.getParameter("xq");
	String weekStr = request.getParameter("week");
	int week = 0;//第几周
	Semester semester = courseQuery.querySemester();
	if (xn == null) {
		xn = semester.getXn();//学年
	}
	if (xq == null) {
		xq = semester.getXq()+"";//学期
	}
	if (weekStr != null) {
		week = Integer.parseInt(weekStr);
	} else {
		week = semester.getCurrentWeek();
	}
	String xgh = Utils.getCurrentUserId(request);//学工号
	//System.out.println("xn=="+xn+";xq=="+xq+";xgh=="+xgh+";week=="+week);
	Map dispalyRecords = courseQuery.queryCourseData(xn,xq,xgh,week);
	Map map = new HashMap();
	
 %>
 
<table width="100%"  border="1" cellspacing="0" cellpadding="0" id="kcb" bordercolor="#cccccc">
  <tr>
    <td colspan="9" style="text-align: center" >
    	<table width="100%" cellpadding="0" cellspacing="0" border="0">
    		<tr>
    			<td width="20"><img style="cursor: hand;cursor: pointer;" onclick="doSubmit(-1)" src="../images/jiantou.jpg"></td>
    			<td class="title"><%=semester.getXn() %>年&nbsp;第<%=semester.getXq() %>学期&nbsp;第<%=week %>周</td>
    			<td width="20"><img style="cursor: hand;cursor: pointer;" src="../images/jiantou_r.jpg" onclick="doSubmit(1)" ></td>
    		</tr>
    	</table>
    	<input type="hidden" id="xn" value="<%=semester.getXn() %>" />
    	<input type="hidden" id="xq" value="<%=semester.getXq() %>" />
    	<input type="hidden" id="week" value="<%=week %>" />
    </td>
  </tr>
  <tr>
    <th colspan="2" width="6%" >时间</th>
    <th width="13%" >一</th>
    <th width="13%" >二</th>
    <th width="13%" >三</th>
    <th width="13%" >四</th>
    <th width="13%" >五</th>
    <th width="13%" >六</th>
    <th width="13%" >日</th>
  </tr>
  
<% for (int i = 1; i < 14; i++) {
	int rowspan = 1;
	String colStr = "&nbsp;";
	if (i == 1) {//上午
		rowspan = 5;
		colStr="上午";
	}
	if (i == 6 || i == 10) {//中午或者晚上
		rowspan = 4;
		if (i == 6) {
			colStr = "下午";
		} else if (i == 10) {
			colStr = "晚上";
		}
			
	}	
	%>
	  <tr>
	    <%if (i == 1 || i == 6 || i == 10) {%><td rowspan="<%=rowspan %>"><%=colStr %></td><%} //输出第一列%>
	    <td><%=i %></td><!-- 输出第二列 -->
	    <%for (int w = 1; w <= 7; w++) { //循环星期一到星期天
	    	Map rowspanRecord = (Map)dispalyRecords.get(w+"_"+i);
	    %>
		    <%
		    	if (rowspanRecord != null && map.get(w+"_"+i) == null) {//输出课程表
		    		String rowspanInteger = (String)rowspanRecord.get("SKCD");
		    		int rowspanInt = Integer.parseInt(rowspanInteger);
		    		for (int s = i+1; s < i+rowspanInt; s++) {
		    			map.put(w+"_"+s,"0");//设置后续的表格不给输出
		    		}
		    		String style = "course";
		    		if (rowspanRecord.get("currentDay") != null) {
		    			style = "course current";
		    		}
		    %>
	    		<td rowspan="<%=rowspanInt %>" title="<%=rowspanRecord.get("displayInfo") %>"  class="<%=style %>">&nbsp;
	    		</td>
		    <%} else { %>
		    	<%if (map.get(w+"_"+i) == null) {//判断是否已经由前面已经输出表格 %><td>&nbsp;</td><%} %>
		    <% } %>
	    <%} %>
	    
	  </tr>		
<% } %>
</table>

</BODY>
</html>
